<?php
declare (strict_types = 1);

namespace app\controller;

use think\Request;
use app\BaseController;
use think\facade\View;
use think\facade\Session;
use app\model\SettingUser as UserModel;
use app\middleware\CheckLogin;

class Profile extends BaseController
{
    // 注册控制器中间件
    protected $middleware = [CheckLogin::class];

    /**
     * 显示资源列表
     * @param  int  $id
     * @return \think\Response
     */

    public function index($id)
    {
        //提取用户信息
        $userData = UserModel::find($id);
        View::assign('userData',$userData);

        return view('index'); 
    }
    /**
     * 保存更新的资源
     *
     * @param  \think\Request  $request
     * @param  int  $id
     * @return \think\Response
     */
    public function update(Request $request, $id)
    {
        $data = request()->param();
        if(!empty($data['password'])){
            $data['password'] = md5($data['password']);
        }else{
            unset($data['password']);
        }
        $result = UserModel::update($data);//调用create方法写入数据库
        if($result == false){
            return 0;
        }else{
            return $result->id;
        }
    }
}
